<template>
  <div style="margin-top:30px">
    <el-form ref="form" :rules="rules" :model="form" label-width="80px">
      <el-row>
        <el-col :span="20">
          <div class="grid-content bg-purple">
            <el-form-item label="商品名称" style="margin-right:15px" label-width="100px" prop="name">
              <el-input v-model="form.name" placeholder="请输入商品名称" style="width:100%" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="20">
          <div class="grid-content bg-purple">
            <el-form-item label="消耗积分" style="margin-right:15px"  label-width="100px" prop="points">
              <el-input v-model="form.points" placeholder="请输入消耗积分" style="width:100%"/>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="funcSubmit" :disabled="isDisable" plain>确 定</el-button>
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import {pointsExchangeGoodsUpdate } from "@/api/integralManage/redeemGift"

Vue.use(VXETable)
export default {
  props:{
    operationList: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      isDisable:false,   //确定键显示按钮

      form: {
        code: this.operationList.code,
        name: this.operationList.name,
        points: this.operationList.points
      },
      rules: {
        name: [
          {required: true, message: '请输入商品名称', trigger: 'blur'},
        ],
        points: [
          {required: true, message: '请输入消耗积分', trigger: 'blur'},
        ]
      },
    }
  },
  created() {

  },
  methods: {
    // 提交
    funcSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          let arr = this.form
          for(let key in arr ){
            if(arr[key] === false){
              arr[key] = 0
            }
            if(arr[key] === true){
              arr[key] = 1
            }
          }
          const data = arr

          this.isDisable = true
          pointsExchangeGoodsUpdate(data).then(response => {
            this.$message({ message: response.msg, type: 'success' })
            this.$emit('fatherEditMethod')
            this.isDisable = false
          }).catch(() => this.isDisable = false)
        } else {
          return false
        }
      })

    },

    // 取消
    funcCancel() {
      this.$emit('fatherCancelMethod', 'edit')
    }

  }
}
</script>
<style lang="scss" scoped>
.dialog-footer {
  margin: 15px 0 15px 0;
  width: 90px;
  float: right;
}
</style>
